package player

import (
	"GameServer/Common/data"
	"GameServer/Common/utils"
	"GameServer/Game/errors"
	"GameServer/Game/lib"
	"GameServer/Game/sp"
)

// 8553 不扣钱，购买Boss礼包
func (p *Player) BossPaidPackBuyRequest(req *sp.BossPaidPackBuyRequest) (res *sp.BossPaidPackBuyResponse) {
	buyingPackId, ap, uProp, resGoods, boxResList, err := lib.BuyBossPack("BossPaidPackBuyRequest", p.User, req.PackId, p.Send)
	if err != nil {
		res = &sp.BossPaidPackBuyResponse{
			Errcode: errors.ErrCode(err),
		}
		return
	}
	buyingPackConfig, err := lib.GetPaidPropsPacksConfig(buyingPackId)
	if err == nil {
		// 首充状态设置
		if p.User.FirstReChargeStatus == 0 && int64(buyingPackConfig.Typ) != data.PaidPropsEnum.FreePack {
			p.User.SetFirstRechargeStatus(1)
		}
	}
	//fmt.Printf("购买礼包 %d,FirstStatus %d.packType %d \n", req.Tid, p.User.FirstReChargeStatus, buyingPackConfig.Typ)
	res = &sp.BossPaidPackBuyResponse{
		Errcode:             0,
		Lst:                 lib.FormatBossPacktSps(ap),
		Res:                 lib.FormatGoodsInfoSps(resGoods),
		BoxRes:              lib.FormatBoxResSps(boxResList),
		FirstReChargeStatus: p.User.FirstReChargeStatus,
	}
	p.TimelyUpdateProp(req.GetType(), uProp)
	utils.AsyncFunc(func() {
		p.UpdateProp(req.GetType(), uProp)
	})
	return
}
